// logs.js
import env from "../../utils/env";
const util = require('../../utils/util.js')
//本地服务器地址
var socketOpen = false;
Page({
  data: {
    productList: [],
    stateNo:'2',
    userId:'',
  },
  initProductList()
  {
    wx.showLoading({
      title: '订单查询中，请稍后',
    });
    var thirdSession = wx.getStorageSync('third_session');
    var Authorization = wx.getStorageSync('access_token');
    var _this=this;
    var orderInfo = {"thirdSession":thirdSession,"orderStatus":_this.data.stateNo}
    wx.request({
      url: env.api_host+ '/identify/order/listByStatus',
      method:'GET',
      data: {
        orderInfo: orderInfo,
      },
      header: {
        Authorization: Authorization,
      },
      success:function(res){
        var orderCount = res.data.rows.length;
        if(orderCount !=0){
          wx.hideLoading();
          _this.setData({productList:res.data.rows});
        }else{
          wx.showModal({
            title: '温馨提示',
            content: '您暂时没有有效订单',
            showCancel:'false'
          })
          wx.hideLoading();

        }
      },
      fail:function (res) {
        
      },
      complete:function (res) {
        
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initProductList();
  },
  changeOrderList(e){
    var _this=this;
    var status = e.currentTarget.id;
    var thirdSession = wx.getStorageSync('third_session');
    var Authorization = wx.getStorageSync('access_token');
    var orderInfo = {"thirdSession":thirdSession,"orderStatus":status}
    _this.setData({
      stateNo:e.currentTarget.id,
    });
    
    wx.request({
      url: env.api_host+ '/identify/order/listByStatus',
      method:'GET',
      data: {
        orderInfo: orderInfo,
      },
      header: {
        Authorization: Authorization,
      },
      success:function(res){
        console.log(res.data.rows);
        var products=res.data.rows;
        _this.setData({
          productList:products
        });
      },
      fail:function (res) {
        
      },
      complete:function (res) {
        
      }
    })
  },
})
